package com.wms.service.impl;

import com.wms.domain.Dep;
import com.wms.mapper.DepMapper;
import com.wms.mapper.EmpMapper;
import com.wms.service.DepService;
import com.wms.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DepServiceImpl implements DepService {

    @Autowired
    private DepMapper depMapper;
    @Autowired
    private EmpMapper empMapper;

    @Override
    public List<Dep> find() {
        return depMapper.findAll();
    }

    @Log
    @Override
    public void delete(int id) {
        //部门删除的同时，部门下的员工也删除
        depMapper.delete(id);
        empMapper.deleteByDeptId(id);
    }

    @Log
    @Override
    public void add(Dep dep) {
        dep.setCreateTime(LocalDateTime.now());
        dep.setUpdateTime(LocalDateTime.now());
        depMapper.add(dep);
    }

    @Override
    public Dep findByid(int id) {
        return depMapper.findByid(id);
    }

    @Override
    public void update(Dep dep) {
        dep.setUpdateTime(LocalDateTime.now());
        depMapper.update(dep);
    }

}
